package pl.pelcra.cesar.spider.webcrawler.interfaces;

import java.util.HashMap;

import pl.pelcra.cesar.data.interfaces.ICommonData;
import pl.pelcra.cesar.spider.data.MapLangUrl;
import pl.pelcra.cesar.tools.Tools;
import edu.uci.ics.crawler4j.url.WebURL;

/**
 * base class that should be overwritten by class with crawl task
 * 
 * @author margielewski
 * 
 */
public class BasePageWebTasks {

	private WebTask mainWebTask;
	private HashMap<String, String> mapParams = new HashMap<String, String>();

	private ICommonData<MapLangUrl> spiderThreadData = null;

	/**
	 * parameterless constructor
	 */
	public BasePageWebTasks() {
	}

	/**
	 * 
	 * @param parameters
	 *            parameters from configuration file
	 */
	public BasePageWebTasks(String parameters) {
		parseParameters(parameters);
	}

	/**
	 * 
	 * @return return main webTask
	 */
	public WebTask getMainWebTask() {
		return this.mainWebTask;
	}

	/**
	 * 
	 * @return return map key - value of parameters from configuration files
	 */
	public HashMap<String, String> getMapParams() {
		return this.mapParams;
	}

	/**
	 * 
	 * @return return object with thread data
	 */
	public ICommonData<MapLangUrl> getSpiderThreadData() {
		return this.spiderThreadData;
	}

	/**
	 * initialize base webTask
	 * 
	 * @param startWebUrl
	 *            first webUrl to start crawls page
	 * @param spiderThreadData
	 *            object to exchange data of MapLangUrls
	 */
	public void init(WebURL startWebUrl,
			ICommonData<MapLangUrl> spiderThreadData) {
		throw new UnsupportedOperationException(
				"In class BasePageWebTasks implment method 'init(WebURL startWebUrl, SpiderThreadData threadData)'");
	}

	private void parseParameters(String parameters) {
		this.mapParams = Tools.parseParameters(parameters);
	}

	/**
	 * set main task
	 * 
	 * @param webTask
	 *            main task that starts process page
	 */
	public void setMainWebTask(WebTask webTask) {
		this.mainWebTask = webTask;
	}

	/**
	 * set spiderThreadData object in base webTask class
	 * 
	 * @param spiderThreadData
	 *            threadData object
	 */
	public void setSpiderThreadData(ICommonData<MapLangUrl> spiderThreadData) {
		this.spiderThreadData = spiderThreadData;
	}
}
